package com.cloud.eurekahystrixconsumer.controller;

import com.cloud.eurekahystrixconsumer.service.ProviderService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.netflix.hystrix.contrib.javanica.conf.HystrixPropertiesManager;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author kangwen
 */
@DefaultProperties(defaultFallback = "fallback")
@RestController
@RequestMapping("consumer")
public class EurekaHystrixProviderController extends AbstractBaseController {

	@Resource
	private ProviderService providerService;

	@HystrixCommand(commandProperties = {
			@HystrixProperty(name = HystrixPropertiesManager.EXECUTION_ISOLATION_THREAD_TIMEOUT_IN_MILLISECONDS, value = "1000")})
	@GetMapping("/hystrix")
	public String hystrix() {
		return providerService.hystrix();
	}

	@GetMapping("/hello")
	public String hello() {
		return providerService.hello();
	}

}
